package common

import (
	"context"
	"errors"
	commonDto "git.mycaigou.com/gfyx/micro-gfyx-mp-api/infrastructure/dto/common"
	commonRepo "git.mycaigou.com/gfyx/micro-gfyx-mp-api/infrastructure/repository/common"
	pb "git.mycaigou.com/gfyx/micro-gfyx-mp-api/proto/micro_gfyx_user_service_proto/micro-gfyx-user-service"
)

type miniProgramService struct {
	miniRepo commonRepo.MiniProgramRepositoryIface
}

// NewMiniProgramService 创建构造函数
func NewMiniProgramService(miniRepo commonRepo.MiniProgramRepositoryIface) MiniProgramServiceIface {
	return &miniProgramService{
		miniRepo: miniRepo,
	}
}

func (s *miniProgramService) GetQrCodeInfoById(ctx context.Context, request *commonDto.GetQrCodeInfoByIdRequest) (*commonDto.GetQrCodeInfoByIdResponse, error) {
	resp, err := s.miniRepo.GetQrCodeInfoById(ctx, &pb.GetQrCodeInfoByIdRequest{
		Id: request.QrId,
	})
	if err != nil {
		return nil, err
	}
	if resp == nil || resp.Id == 0 {
		return nil, errors.New("获取qrcode信息失败")
	}
	return &commonDto.GetQrCodeInfoByIdResponse{
		Id:    resp.Id,
		Page:  resp.Page,
		Scene: resp.Scene,
	}, nil
}
